<template>
	<view>
		<!-- 搜索部分 -->
		<view class="search">
			<my-search @click="gotoSearch"></my-search>
		</view>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">
					<image :src="item.image_src" mode=""></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 导航分类区域 -->
		<view class="nav-list">
			<view class="nav-list-item" v-for="(item,index) in navList" :key="index" @click="navListItemClick(item)">
				<image :src="item.image_src" mode="" class="nav-img"></image>
			</view>
		</view>
		<!-- 楼层部分 -->
		<view class="floor-list">
			<view class="floor-list-item" v-for="(item,index) in floorList" :key="index">
				<image :src="item.floor_title.image_src" class="floor-title"></image>
				<view class="floor-list-box">
					<navigator class="floor-list-left" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
					</navigator>
					<view class="floor-list-right" >
						<navigator class="floor-list-right-item" v-for="(item1,index1) in item.product_list" :key="index1"   v-if="index1 !== 0" :url="item1.url">
							<image :src="item1.image_src" mode="widthFix" :style="{width:item1.image_width + 'rpx'}"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixin/tabbar-badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				// 轮播图数据
				swiperList:[],
				// 分类数据
				navList:[],
				// 楼层数据
				floorList:[]
			};
		},
		onLoad() {
			this.getSwiperList();
			this.getNavList();
			this.getFloorList()
		},
		methods:{
			// 获取轮播图数据
	    async getSwiperList(){
			const {data:res} = await uni.$http.get('api/public/v1/home/swiperdata');
			if(res.meta.status !== 200){
				return uni.$showMsg();
			}
			this.swiperList = res.message;
			// console.log(this.swiperList)
			uni.$showMsg('数据请求成功')
			},
			// 获取分类导航数据
			async getNavList(){
				const {data:res} = await uni.$http.get('api/public/v1/home/catitems')
				// console.log(res)
				if(res.meta.status !== 200){
					return uni.$showMsg();
				}
				this.navList = res.message;
				// console.log(this.navList)
			},
			// 点击分类导航item的回调
			navListItemClick(item){
				if(item.name == '分类'){
					uni.switchTab({
						url:'../cate/cate'
					})
				}
			},
			// 获取楼层数据
			async getFloorList(){
				const {data:res} = await uni.$http.get('api/public/v1/home/floordata');
				// console.log(res)
				if(res.meta.status !== 200){
					return uni.$showMsg();
				}
				// 对数据进行处理
				res.message.forEach(item=>{
					item.product_list.forEach(prod=>{
						prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1]
					})
				})
				this.floorList = res.message;
				console.log(this.floorList)
			},
			// 跳转到搜索页
			gotoSearch(){
				uni.navigateTo({
					url:"../../subpkg/search/search"
				})
			}
			
		}
	}
</script>

<style lang="scss">
	.search{
		position: sticky;
		top: 0;
		z-index: 999;
	}
swiper{
	height: 330rpx;
	.swiper-item,
	image{
		width: 100%;
		height: 100%;
	}
}
.nav-list{
	display: flex;
	justify-content: space-around;
	margin: 15px 0;
	background-color: #fff;
	.nav-img{
		width: 138rpx;
		height: 148rpx;
	}
}
.floor-list{
	.floor-title{
		width: 100%;
		height: 60rpx;
	}
	.floor-list-box{
		display: flex;
		.floor-list-right{
			display: flex;
			flex-wrap: wrap;
			justify-content: space-around;
		}
	}
	
}
</style>
